package ConllctionNofair;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * map 不安全
 */
public class mapTest {
    public static void main(String[] args) {
//        1.使用集合类进行安全
//        HashMap<String, String> map = new HashMap<>();
//        Map<String, String> map1 = Collections.synchronizedMap(map);
//        2.使用ConcruenntHashMap 线程安全map
//       ConcruenntHashMap
        ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                map.put(UUID.randomUUID().toString().substring(0,5),"");
                System.out.println(map);
            },i+"").start();
        }




    }

    public int pivotIndex(int[] nums) {
        int left=0,right = 0;
        for (int i = 1; i <nums.length; i++) {
            right+=nums[i];
        }

        for (int i = 0; i < nums.length; i++) {
            if(i != 0){
                right -= nums[i];
                left+=nums[i];
            }else{
                left+=nums[i];
            }
            if(left == right){
                return i;
            }
        }

        return -1;
    }
}
